package com.fw.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fw.annotation.Log;
import com.fw.core.controller.BaseController;
import com.fw.core.domain.AjaxResult;
import com.fw.enums.BusinessType;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import javax.validation.Valid;
import static com.fw.mes.ResultUtils.success;
import com.fw.system.admin.domain.TbAnswerDetail;
import com.fw.system.admin.service.ITbAnswerDetailService;
import com.fw.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import com.fw.core.page.TableDataInfo;

/**
 * 答案Controller
 * 
 * @author yanwei
 * @date 2023-04-04
 */
@Api(tags = "answer_detail")
@RestController
@RequestMapping("/admin/answer_detail")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class TbAnswerDetailController extends BaseController
{
    @Autowired
    private ITbAnswerDetailService tbAnswerDetailService;

    /**
     * 查询答案列表
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:list')")
    @GetMapping("/list")
    @ApiOperation("查询答案列表")
    public TableDataInfo list(TbAnswerDetail tbAnswerDetail)
    {
        startPage();
        List<TbAnswerDetail> list = tbAnswerDetailService.selectTbAnswerDetailList(tbAnswerDetail);
        return getDataTable(list);
    }

    /**
     * 导出答案列表
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:export')")
    @Log(title = "答案", businessType = BusinessType.EXPORT)
    @ApiOperation("导出答案列表")
    @GetMapping("/export")
    public AjaxResult export(TbAnswerDetail tbAnswerDetail)
    {
        List<TbAnswerDetail> list = tbAnswerDetailService.selectTbAnswerDetailList(tbAnswerDetail);
        ExcelUtil<TbAnswerDetail> util = new ExcelUtil<TbAnswerDetail>(TbAnswerDetail.class);
        return util.exportExcel(list, "answer_detail");
    }

    /**
     * 获取答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取答案详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbAnswerDetailService.selectTbAnswerDetailById(id));
    }

    /**
     * 新增答案
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:add')")
    @Log(title = "答案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增答案")
    public AjaxResult add(@RequestBody TbAnswerDetail tbAnswerDetail)
    {
        return toAjax(tbAnswerDetailService.insertTbAnswerDetail(tbAnswerDetail));
    }

    /**
     * 修改答案
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:edit')")
    @Log(title = "答案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改答案")
    public AjaxResult edit(@RequestBody TbAnswerDetail tbAnswerDetail)
    {
        return toAjax(tbAnswerDetailService.updateTbAnswerDetail(tbAnswerDetail));
    }

    /**
     * 删除答案
     */
    @PreAuthorize("@ss.hasPermi('admin:answer_detail:remove')")
    @Log(title = "答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除答案")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbAnswerDetailService.deleteTbAnswerDetailByIds(ids));
    }
}
